<template>
  <t-dialog
    header="审核"
    :visible.sync="visible"
    @confirm="onConfirm"
    width="40%"
    :loading="loading"
    :confirmOnEnter="true"
    :onClose="close"
  >
    <t-form :data="formData" :rules="rules" ref="form" layout="vertical" label-align="top" @submit="onSubmit">
      <t-form-item label="审核状态" name="is_audit">
        <t-switch size="large" v-model="formData.is_audit" :custom-value="[1, -1]" :label="['通过', '驳回']"></t-switch>
      </t-form-item>
      <t-form-item label="审核备注" name="is_audit">
        <t-textarea size="large" v-model="formData.audit_msg" placeholder="请输入备注"></t-textarea>
      </t-form-item>
    </t-form>
  </t-dialog>
</template>

<script>
import {agentAuditApi} from "@/api/agent";

export default {
  name: 'ApplyDialog',
  data() {
    return {
      visible: false,
      loading: false,
      formData: {
        is_audit: 1, // 审核（-1 驳回；1 通过）
        audit_msg: '', // 驳回原因
      },
      rules: {

      },
      applyId: '', // 申请id
    }
  },
  mounted() {
  },
  methods: {
    onConfirm() {
      this.$refs.form.submit();
    },
    onSubmit({ validateResult, firstError }) {
      if (validateResult === true) {
        this.handleSubmit()
      } else {
        this.$message.warning(firstError);
      }
    },
    handleSubmit() {
      agentAuditApi(this.applyId, this.formData).then(res=> {
        this.$message.success('提交成功')
        this.$emit('refresh')
      }).catch(err=> {
        console.log('err', err)
      })
    },
    open(applyId) {
      this.applyId = applyId
      this.formData = {
        is_audit: 1, // 审核（-1 驳回；1 通过）
        audit_msg: '', // 驳回原因
      }
      this.visible = true
    },
    close() {
      this.visible = false
    }
  }
}
</script>

<style lang="less" scoped>

</style>
